#define _CRT_SECURE_NO_WARNINGS 1
#include"sort.h"

void PrintArray(int* a, int size)
{
	for (int i = 0; i < size; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

void swap(int* p1, int* p2)
{

	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

void InsertSort(int* a, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int end = i + 1;
		int tmp = a[end];
		while (end > 0)
		{
			if (tmp < a[end - 1])
			{
				a[end] = a[end-1];
				end--;
				
			}
			else
				break;
		}
		a[end] = tmp;
	}
}

void ShellSort(int* a, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int end = i + 1;
		int tmp = a[end];
		while (end > 0)
		{
			if (tmp < a[end - 1])
			{
				a[end] = a[end - 1];
				end--;

			}
			else
				break;
		}
		a[end] = tmp;
}

void QuickSort(int* a, int left, int right)
{
	if (left >= right)
		return;
	int keyi = left;
	int begin = left;
	int end = right;
	while (end > begin)
	{
		while (end > begin && a[end] >= a[keyi])
		{
			end--;
		}
		while (end > begin && a[begin] <= a[keyi])
		{
			begin++;
		}
		swap(&a[begin], &a[end]);
	}
	swap(&a[keyi], &a[end]);
	keyi = begin;
	QuickSort(a, left, keyi - 1);
	QuickSort(a, keyi + 1, right);

}